package OpenFeign知识;
import feign.Feign;
import feign.gson.GsonDecoder;
import feign.gson.GsonEncoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.Logger;
import feign.Response;

public class FeignClientDemo {

    public static void main(String[] args) {
        // 创建 Feign 客户端
        MyApiClient client = Feign.builder()
                .encoder(new GsonEncoder()) // 设置编码器
                .decoder(new GsonDecoder()) // 设置解码器
                .logLevel(Logger.Level.FULL)   // 日志详细级别
                .target(MyApiClient.class, "http://localhost:8080");  // 设置服务的 URL

        // 创建一个用户
        User newUser = new User("123", "John Doe", 30);
        System.out.println("Sending POST request to create user...");

        try {
            User createdUser = client.createUser(newUser);
            System.out.println("Created User: " + createdUser);
        } catch (Exception e) {
            e.printStackTrace();  // 输出异常信息
        }

        // 获取用户信息
        try {
            User retrievedUser = client.getUser("123");
            System.out.println("Retrieved User: " + retrievedUser);
        } catch (Exception e) {
            e.printStackTrace();  // 输出异常信息
        }
    }
}
